home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / inventor / sharedSV / SvManipList.c++ < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  5.2 KB  |  200 lines

  1. /*
  2.  * Copyright (c) 1991, 1992 Silicon Graphics, Inc.
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that the name of Silicon Graphics may not be used in any advertising or
  7.  * publicity relating to the software without the specific, prior written
  8.  * permission of Silicon Graphics.
  9.  *
  10.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
  11.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
  12.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  13.  *
  14.  * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  15.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
  16.  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE
  17.  * POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN
  18.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  19.  */
  20.  
  21. /*
  22.  * Copyright (C) 1990,91,92   Silicon Graphics, Inc.
  23.  *
  24.  * 
  25.  _______________________________________________________________________
  26.  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
  27.  |
  28.  |   $Revision: 1.1000 $
  29.  |
  30.  |   Classes:    SvManipList
  31.  |
  32.  |   Author(s):    David Mott
  33.  |
  34.  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
  35.  _______________________________________________________________________
  36.  */
  37.  
  38. #include <Inventor/SbPList.h>
  39. #include <Inventor/SoPath.h>
  40. #include <Inventor/manips/SoManipulator.h>
  41. #include "SvManipList.h"
  42.  
  43.  
  44. // a path/manip pair
  45. typedef struct SvPathManipPair {
  46.     SoPath        *path;
  47.     SoManipulator   *manip;
  48. } SvPathManipPair;
  49.  
  50. ////////////////////////////////////////////////////////////////////////
  51. //
  52. // Constructor
  53. //
  54. // Use: public
  55. SvManipList::SvManipList()
  56. //
  57. ////////////////////////////////////////////////////////////////////////
  58. {
  59.     list = new SbPList;
  60. }
  61.  
  62. ////////////////////////////////////////////////////////////////////////
  63. //
  64. // Destructor
  65. //
  66. // Use: public
  67. SvManipList::~SvManipList()
  68. //
  69. ////////////////////////////////////////////////////////////////////////
  70. {
  71.     delete list;
  72. }
  73.  
  74. ////////////////////////////////////////////////////////////////////////
  75. //
  76. // Append adds the path/manip pair to the list.
  77. // This ref()'s both the path and the manip.
  78. //
  79. // Use: public
  80. int
  81. SvManipList::getLength() const
  82. //
  83. ////////////////////////////////////////////////////////////////////////
  84. {
  85.     return list->length();
  86. }
  87.  
  88. ////////////////////////////////////////////////////////////////////////
  89. //
  90. // Append adds the path/manip pair to the list.
  91. // This ref()'s both the path and the manip.
  92. //
  93. // Use: public
  94. void
  95. SvManipList::append(SoPath *p, SoManipulator *m)
  96. //
  97. ////////////////////////////////////////////////////////////////////////
  98. {
  99.     SvPathManipPair *pair = new SvPathManipPair;
  100.     
  101.     pair->path = p;
  102.     pair->manip = m;
  103.     p->ref();
  104.     m->ref();
  105.     
  106.     list->append(pair);
  107. }
  108.  
  109. ////////////////////////////////////////////////////////////////////////
  110. //
  111. // Find locates the first path/manip pair whose path is p,
  112. // and returns the index in the list of that pair.
  113. //
  114. // Use: public
  115. int
  116. SvManipList::find(SoPath *p) const
  117. //
  118. ////////////////////////////////////////////////////////////////////////
  119. {
  120.     int which = -1;
  121.     
  122.     for (int i = 0; (i < list->length()) && (which == -1); i++) {
  123.     SvPathManipPair *pair = (SvPathManipPair *) (*list)[i];
  124.     if (*pair->path == *p)
  125.         which = i;
  126.     }
  127.     
  128.     return which;
  129. }
  130.  
  131. ////////////////////////////////////////////////////////////////////////
  132. //
  133. // Find locates the first path/manip pair whose manip is m,
  134. // and returns the index in the list of that pair.
  135. //
  136. // Use: public
  137. int
  138. SvManipList::find(SoManipulator *m) const
  139. //
  140. ////////////////////////////////////////////////////////////////////////
  141. {
  142.     int which = -1;
  143.     
  144.     for (int i = 0; (i < list->length()) && (which == -1); i++) {
  145.     SvPathManipPair *pair = (SvPathManipPair *) (*list)[i];
  146.     if (pair->manip == m)
  147.         which = i;
  148.     }
  149.     
  150.     return which;
  151. }
  152.  
  153. ////////////////////////////////////////////////////////////////////////
  154. //
  155. // Remove removes the path/manip pair specified by which index from
  156. // the list. This unref()'s both the path and the manip.
  157. //
  158. // Use: public
  159. void
  160. SvManipList::remove(int which)
  161. //
  162. ////////////////////////////////////////////////////////////////////////
  163. {
  164.     SvPathManipPair *pair = (SvPathManipPair *) (*list)[which];
  165.     
  166.     pair->path->unref();
  167.     pair->manip->unref();
  168.     
  169.     list->remove(which);
  170. }
  171.  
  172. ////////////////////////////////////////////////////////////////////////
  173. //
  174. // This returns the path in the path/manip pair specified by which index.
  175. //
  176. // Use: public
  177. SoPath *
  178. SvManipList::getPath(int which) const
  179. //
  180. ////////////////////////////////////////////////////////////////////////
  181. {
  182.     SvPathManipPair *pair = (SvPathManipPair *) (*list)[which];
  183.     return (pair->path);
  184. }
  185.  
  186. ////////////////////////////////////////////////////////////////////////
  187. //
  188. // This returns the manip in the path/manip pair specified by which index.
  189. //
  190. // Use: public
  191. SoManipulator *
  192. SvManipList::getManip(int which) const
  193. //
  194. ////////////////////////////////////////////////////////////////////////
  195. {
  196.     SvPathManipPair *pair = (SvPathManipPair *) (*list)[which];
  197.     return (pair->manip);
  198. }
  199.  
  200.